<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link href="../../css/bootstrap.css" rel="stylesheet" />
<link href="../../css/cover.css" rel="stylesheet" />
<link href="../../css/font-awesome.min.css" rel="stylesheet" />
<title>荆州千网汇信息科技有限公司</title>
<script src="../../js/jquery-2.2.3.min.js"></script>
<script src="../../js/jquery.flexslider-min.js"></script>
<script src="../../js/rem.js"></script>
<script src="../../js/itnetcao.js"></script>
<link href="../../js/layui/css/layui.css" rel="stylesheet" />
<link href="../../js/donghua/animsition.min.css" rel="stylesheet" />
<script src="../../js/donghua/animsition.min.js"></script>
<link rel="stylesheet" href="../../css/minirefresh.css" />
<link rel="stylesheet" href="../../css/common.css" />
<script type="text/javascript" src="../../js/minirefresh.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/layui/layui.js"></script>

<title>我的交易</title>
<style type='text/css'>
#Show dt {
	margin: 0.5rem 0.1rem;
}

#Show dd p {
	margin: 0.1rem 0.1rem;
}

#Show dl img {
	border-radius: 50%;
	width: 1.5rem;
	height: 1.5rem;
}

#Show dl {
	margin-left: 0.2rem;
	display: flex;
}

#Show dl dd {
	margin-left: 0.5rem;
}

#Show button {
	border-radius: 1.5rem;
	outline-color: #FFFFFF;
	width: 2rem;
	color: #FFFFFF;
	background-color: #FFC90C;
}

.ShowName {
	font-size: 0.2rem;
}

.ShowOne {
	font-size: 0.2rem;
}

.ShowT {
	font-size: 0.2rem;
}

#ShowD {
	margin: 0.2rem;
}

#ShowP {
	margin: 0.2rem;
}
</style>
</head>
<body style='width:100%;height:100%;'>
	<div class="page_top01 relative">
        <h3 class="text-center">我的交易</h3>
        <a href="javascript:;" class="animsition-link" data-animsition-out-class="fade-out-right" data-animsition-out-duration="500" onclick="history.go(-1)">
            <img src="../../images/icon_left.png" class="img-responsive reture_img" /></a>
    </div>
    <!--layui-tab-card-->
    <div align='center layui-tab-brief'>
		<div class="layui-tab" lay-filter="changeExchange">
			<ul class="layui-tab-title">
				<li></li>
				<li class="layui-this">求购</li>
				<li></li>
				<li></li>
				<li>出售</li>
			</ul>
			<div class="layui-tab-content">
				<div class="layui-tab-item"></div>
				<div class="layui-tab-item layui-show loadUserDataQiuGou"></div>
				<div class="layui-tab-item"></div>
				<div class="layui-tab-item"></div>
				<div class="layui-tab-item loadUserDataChuShou"></div>
			</div>
		</div>
	</div>
<script type="text/javascript" src="../../js/clipboard.min.js"></script>
</body>
<script type='text/javascript'>

var options = {
	userId : jQuery.parseJSON(localStorage.getItem("miningmachine_user")).userId,
	iphone : jQuery.parseJSON(localStorage.getItem("miningmachine_user")).userIphone,
	a_url : localStorage.getItem("url") + "/buy/controller/BuyOrSellFindPageBillAPP.do",
	a_data : "",
	a_pc : 1,
	a_ps : 100,
	a_tr : null,
	a_tp : null,
	a_order : "buyState desc, buyDate desc",
	b_url : localStorage.getItem("url") + "/buy/controller/BuyOrSellFindPageBillAPP.do",
	b_data : "",
	b_pc : 1,
	b_ps : 10,
	b_tr : null,
	b_tp : null,
	b_order : "buyState desc, buyDate desc",
	layer : null,
	init : function() {
		// 初始化
		var tis = this;

		layui.use(['element', 'layer'], function(){
			tis.layer = layui.layer;
			/*var element = layui.element;
			var layid = location.hash.replace(/^#changeExchange=/, '');
			element.tabChange('changeExchange', layid);
			element.on('tab(changeExchange)', function(){
				location.hash = 'changeExchange='+ this.getAttribute('lay-id');
			});
			*/
		});

		tis.loadUserDataQiuGou();

		tis.loadUserDataChuShou();

		$(document).click(function(e) {
			var e = e || window.event;
			var target = e.target || e.srcElement;
			var targetName = target.nodeName.toLowerCase();



			var html = "" +

				"<div align='center' class='layui-fluid layui-form' style='margin:10px;margin-top:30px;height:90%;width:90%;'>" +
					"<div class='layui-row layui-col-space15'>" +
						"<div class='layui-form-item' style='margin-left:0px;margin-right:0px;padding-left:0px;padding-right:0px;'>" +
							"<label class='layui-form-label' style='width:60px;margin-left:0px;margin-right:0px;padding-left:0px;padding-right:0px;'>手机</label>" +
							"<div class='layui-input-inline' style='width:140px;margin-left:0px;margin-right:0px;padding-left:0px;padding-right:0px;'>" +
								"<input type='text' value='"+tis.iphone+"' disabled placeholder='请输入您的手机号' class='layui-input jiaoYiIphone' style='background:#CCC;'/>" +
							"</div>" +
						"</div>" +
					"<div>" +

					"<div class='layui-row layui-col-space15'>" +
						"<div class='layui-form-item' style='margin-left:0px;margin-right:0px;padding-left:0px;padding-right:0px;'>" +
							"<label class='layui-form-label' style='width:60px;margin-left:0px;margin-right:0px;padding-left:0px;padding-right:0px;'>验证码</label>" +
							"<div class='layui-input-inline' style='width:140px;margin-left:0px;margin-right:0px;padding-left:0px;padding-right:0px;'>" +
								"<input type='text' placeholder='请输入验证码' class='layui-input jiaoYiCode' />" +
							"</div>" +
						"</div>" +
					"<div>" +

					"<div class='layui-row layui-col-space15'>" +
						"<div class='layui-form-item' style='margin-left:0px;margin-right:0px;padding-left:0px;padding-right:0px;'>" +
							"<label class='layui-form-label' style='width:60px;margin-left:0px;margin-right:0px;padding-left:0px;padding-right:0px;'>交易密码</label>" +
							"<div class='layui-input-inline' style='width:140px;margin-left:0px;margin-right:0px;padding-left:0px;padding-right:0px;'>" +
								"<input type='password' placeholder='请输入您的交易密码' class='layui-input jiaoYiPassword' />" +
							"</div>" +
						"</div>" +
					"<div>" +

				"</div>" +
			"";


			if($(target).is(".quitBill")) {
				// 用户取消卖出或请购

				var id = $(target).attr("data-id");
				var type = $(target).attr("data-type");

				tis.userQuitBill(id, type);
			}

			if($(target).is(".userConfirm")) {


				tis.layer.open({
					type : 1,
					content : html,
					area : ['90%', '60%'],
					title : false,
					btn : ["获取验证码", "提交"],
					yes : function(index, layero) {
						// 发送验证码
						if($(".layui-layer-btn0").is(".layui-btn-disabled")) {
							return;
						}
						$(".layui-layer-btn0").addClass("layui-btn-disabled");
						var a = 120;
						var _this = $(".layui-layer-btn0");
						var n = window.setInterval(function() {
							a = a - 1;
							$(_this).text(a + "秒后重新发送");
							if(a == 0) {
								$(_this).removeClass("layui-btn-disabled");
								window.clearInterval(n);
								$(_this).text("获取验证码");
							}
						}, 1000);


						var b = 120;
						tis.guoqidingshiqi = window.setInterval(function() {
							b = b - 1;
							if(b == 0) {
								sessionStorage.setItem("guoqi", "yes");
							}
						}, 1000)

						var iphone = $(".jiaoYiIphone").val();

						localStorage.setItem("iphoneCode", "");

						$.ajax({
							url : localStorage.getItem("url") + "/user/controller/getUserAuthReIPhoneCodeAPP.do",
							type:"post",
							data : "iphone=" + iphone,
							dataType : 'json',
							success:function(json) {
								if(json.state == true) {
									localStorage.setItem("iphoneCode", json.bean);
									tis.layer.msg(json.value, {icon:1, time:1000})
								}else {
									tis.layer.msg("失败:" + json.value, {icon:1, time:1000})
								}
							}
						});

					},
					btn2 : function(index, layero) {
						if(localStorage.getItem("iphoneCode") == undefined) {
							alert("请先发送手机验证码.");
							return false;
						}
						if($(".jiaoYiCode").val().trim().length == 0) {
							alert("请输入验证码");
							return false;
						}
						if($(".jiaoYiCode").val().trim() != localStorage.getItem("iphoneCode").trim()) {
							alert("验证码不正确");
							return false;
						}
						if($(".jiaoYiPassword").val().trim().length == 0) {
							alert("请输入交易密码");
							return false;
						}

						var id = $(target).attr("data-id");
						var type = $(target).attr("data-type");
						var m = "";
						if(type == 1) {
							m = "出售";
						}else {
							m = "买入";
						}

						if(confirm("您确定" + m + "?")) {
							// 用户确定请购或确定出售
							var url = localStorage.getItem("url") + "/buy/controller/UserIsBillSetState.do";
							var data = "op=confirmBuy&billUserId=" + tis.userId + "&buyId=" + id + "&jiaoYiPassword=" + $(".jiaoYiPassword").val().trim();
							itcao.itGetAjaxBigData(url, data).done(function(result) {
								var json = jQuery.parseJSON(result);
								if(json.state == true) {
									alert(m + "成功");
									if(type == 2) {
										tis.loadUserDataQiuGou();
									}
									if(type == 1) {
										tis.loadUserDataChuShou();
									}
								}else {
									alert(m + "失败:" + json.value);
									return false;
								}
							})
						}else {
							return false;
						}

					}
				})


			}



			// 显示用户的联系方式
			/*if($(target).is(".showWealth")) {
				var user_id = $(target).attr("data-id");
				var url = localStorage.getItem("url") + "/user/controller/UserPropertyAndUserInfoFindAllAPP.do";
				var data = "userId=" + user_id;

				itcao.itGetAjaxBigData(url, data).done(function(result) {

					var json = jQuery.parseJSON(result);
					if(json.state == true) {

						var bean = json.bean;

						if(bean.length == 0) {
							alert("获取用户的信息失败.");
							return;
						}

						var wx = -1;
						var zf = -1;

						for(var i=0; i<bean.length; i++) {
							if(bean[i].proType == 1) {
								zf = i;
							}
							if(bean[i].proType == 2) {
								wx = i;
							}
						}

						if(wx == -1 && zf == -1) {
							alert("用户还没有支付宝和微信信息,您可以拨打该用户的电话索取支付信息.");
						}


						var dianhua =
						"<div class='layui-col-xs12'>" +
							"<div class='layui-form-item'>" +
							    "<label class='layui-form-label'>电话</label>" +
							    "<div class='layui-input-inline'> " +
									"<input type='text' value='"+bean[0].userIphone+"' disabled class='layui-input dianhua_btn'>" +
							    "</div> " +
							    "<div class='layui-form-mid layui-word-aux btn_1'>点击复制</div>" +
							"</div>" +
						"</div> ";


						var wxhtml = "";

						if(wx != -1) {
							wxhtml =
							"<div class='layui-col-xs12'>" +
								"<div class='layui-form-item'>" +
								    "<label class='layui-form-label'>微信账号</label>" +
								    "<div class='layui-input-inline'> " +
										"<input type='text' value='"+bean[wx].proKey+"' disabled class='layui-input weixin_btn'>" +
								    "</div> " +
								    "<div class='layui-form-mid layui-word-aux btn_2'>点击复制</div>" +
								"</div>" +
							"</div> ";
						}
						var zfhtml = "";
						if(zf != -1) {
							zfhtml =
							"<div class='layui-col-xs12'>" +
								"<div class='layui-form-item'>" +
								    "<label class='layui-form-label'>支付账号</label>" +
								    "<div class='layui-input-inline'> " +
										"<input type='text' value='"+bean[zf].proKey+"' disabled class='layui-input zhifubao_btn'>" +
								    "</div> " +
								    "<div class='layui-form-mid layui-word-aux btn_3'>点击复制</div>" +
								"</div>" +
							"</div> ";
						}


						var html = "<div class='layui-fluid layui-form layui-form-pane' style='margin-top:20px;'>" +
							"<div class='layui-row layui-col-space15'>" +
								dianhua +
								wxhtml +
								zfhtml +
							"</div>" +
						"</div>"


						tis.layer.open({
							type : 1,
							content : html,
							area : ['80%', '60%'],
							title : false,
							success : function() {
								var clipboard_1 = new ClipboardJS('.btn_1', {
									text : function() {
										return $(".dianhua_btn").val();
									}
								});
								clipboard_1.on('success', function(e) {
								    alert("复制成功.");
								});
								clipboard_1.on('error', function(e) {
								    alert("非常抱歉,复制功能貌似出现了问题,您可以联系管理员解决.");
								});


								var clipboard_2 = new ClipboardJS('.btn_2', {
									text : function() {
										return $(".weixin_btn").val();
									}
								});
								clipboard_2.on('success', function(e) {
								    alert("复制成功.");
								});
								clipboard_2.on('error', function(e) {
								    alert("非常抱歉,复制功能貌似出现了问题,您可以联系管理员解决.");
								});

								var clipboard_3 = new ClipboardJS('.btn_3', {
									text : function() {
										return $(".zhifubao_btn").val();
									}
								});
								clipboard_3.on('success', function(e) {
								    alert("复制成功.");
								});
								clipboard_3.on('error', function(e) {
								    alert("非常抱歉,复制功能貌似出现了问题,您可以联系管理员解决.");
								});

							}
						})




					}else {
						alert("获取对方信息失败:" + json.value);
					}

				})

			}*/


		})

	},
	// 用户取消请购单或取消出售单
	userQuitBill : function(id, type) {

		var tis = this;
		var url = localStorage.getItem("url") + "/buy/controller/DeleteBuyOrSellAPP.do";
		var data = "userId=" + tis.userId + "&buyId=" + id;

		var m = "";
		if(type == 1) {
			m = "卖出";
		}else {
			m = "收购";
		}

		if(confirm("您确定取消" + m + "信息?")) {
			itcao.itGetAjaxBigData(url, data).done(function(result) {
				var json = jQuery.parseJSON(result);
				if(json.state == true) {
					alert("取消" + m + "成功.");
					if(type == 2) {
						tis.loadUserDataQiuGou();
					}
					if(type == 1) {
						tis.loadUserDataChuShou();
					}
				}else {
					alert("取消" + m + "失败:" + json.value);
				}
			})
		}



	},
	// 加载求购列表
	loadUserDataQiuGou : function() {
		var tis = this;
		$(".loadUserDataQiuGou").empty();
		tis.a_data = "buyUserId=" + this.userId + "&buyType=2" + "&pc=" + tis.a_pc + "&ps=" + tis.a_ps + "&order=" + tis.a_order;
		itcao.itGetAjaxBigData(tis.a_url, tis.a_data).done(function(result) {
			var json = jQuery.parseJSON(result);
			if(json.state == true) {
				for(var i=0; i<json.bean.length; i++) {
					var buyState = json.bean[i].buyState;
					var userImage = "";
					if(itcao.isNull(json.bean[i].userImage) == "") {
						userImage = "../../image/5.jpg";
					}else {
						userImage = localStorage.getItem("url") + "/" + itcao.isNull(json.bean[i].userImage);
					}

					var msg = "";
					if(buyState == 3) {
						msg += "<p class='ShowT'><button style='width:80px;' data-type='2' data-id='"+json.bean[i].buyId+"' class='btn btn-default userConfirm'>买入</button></p>";
						msg += "<p class='ShowT'><button style='width:80px;' data-type='2' data-id='"+json.bean[i].buyId+"' class='btn btn-default quitBill'>取消</button></p>";
					} else if(buyState == 4) {
						msg += "<p class='ShowT'>买家已确认，待卖家确认</p>";
					}


					$(".loadUserDataQiuGou").append(
						"<div id='Show' style='margin-top:20px;'>" +
							"<dl>" +
								"<dt><img src='"+userImage+"'/ ></dt>" +
								"<dd id='ShowP' style='width:70%;'>" +
									"<p class='ShowName'><b>"+json.bean[i].userName+"</b></p>" +
									"<p class='ShowOne'>XTS数量：<span id='ShowOneSpan'>"+json.bean[i].buyNumber+"</span></p>" +
									"<p class='ShowOne'>单价："+json.bean[i].buyPrice+"$</p>" +
									"<p class='ShowOne'>总价："+json.bean[i].buyTotalAmount+"$</p>" +
									"<p class='ShowOne'>成交量：0 &nbsp;好评率：99.49%</p>" +
								"</dd>" +
								"<dd id='ShowD'style='width:30%;'>" +
									"<p class='ShowT'><b>"+json.bean[i].buyCny+" CNT</b></p>" +
									msg +
									//"<p class='ShowT'><button style='width:80px;' data-id='"+json.bean[i].buyUserId+"' class='btn btn-default showWealth'>联系/付款</button></p>" +
								"</dd>" +
							"</dl>" +
							"<hr/>" +
						"</div>"
					);
				}
			}
		})
	},

	// 加载出售列表
	loadUserDataChuShou : function() {
		var tis = this;
		$(".loadUserDataChuShou").empty();
		tis.b_data = "buyUserId=" + this.userId + "&buyType=1" + "&pc=" + tis.b_pc + "&ps=" + tis.b_ps + "&order=" + tis.b_order;
		itcao.itGetAjaxBigData(tis.b_url, tis.b_data).done(function(result) {
			var json = jQuery.parseJSON(result);
			if(json.state == true) {

				for(var i=0; i<json.bean.length; i++) {
					var userImage = "";
					if(itcao.isNull(json.bean[i].userImage) == "") {
						userImage = "../../image/5.jpg";
					}else {
						userImage = localStorage.getItem("url") + "/" + itcao.isNull(json.bean[i].userImage);
					}

					var msg = "";
					if(json.bean[i].buyState == 3) {
						msg = "<p class='ShowT'><button style='width:80px;' data-type='1' data-id='"+json.bean[i].buyId+"' class='btn btn-default userConfirm'>卖出</button></p>";
					}


					$(".loadUserDataChuShou").append(
						"<div id='Show' style='margin-top:20px;'>" +
							"<dl>" +
								"<dt><img src='"+userImage+"'/ ></dt>" +
								"<dd id='ShowP' style='width:70%;'>" +
									"<p class='ShowName'><b>"+json.bean[i].userName+"</b></p>" +
									"<p class='ShowOne'>XTS数量：<span id='ShowOneSpan'>"+json.bean[i].buyNumber+"</span></p>" +
									"<p class='ShowOne'>单价："+json.bean[i].buyPrice+"$</p>" +
									"<p class='ShowOne'>总价："+json.bean[i].buyTotalAmount+"$</p>" +
									"<p class='ShowOne'>成交量：0 &nbsp;好评率：99.49%</p>" +
								"</dd>" +
								"<dd id='ShowD'style='width:30%;'>" +
									"<p class='ShowT'><b>"+json.bean[i].buyCny+" CNT</b></p>" +
									msg +
									"<p class='ShowT'><button style='width:80px;' data-type='1' data-id='"+json.bean[i].buyId+"' class='btn btn-default quitBill'>取消</button></p>" +
									//"<p class='ShowT'><button style='width:80px;' data-id='"+json.bean[i].buyUserId+"' class='btn btn-default showWealth'>联系/付款</button></p>" +
								"</dd>" +
							"</dl>" +
							"<hr/>" +
						"</div>"
					);
				}

			}
		})
	}
}
options.init();
/*
var html =
"<div id='Show' style='margin-top:20px;'>" +
	"<dl>" +
		"<dt><img src='"+userImage+"'/ ></dt>" +
		"<dd id='ShowP' style='width:70%;'>" +
			"<p class='ShowName'><b>"+json.bean[i].userName+"</b></p>" +
			"<p class='ShowOne'>XTS数量：<span id='ShowOneSpan'>"+json.bean[i].buyNumber+"</span></p>" +
			"<p class='ShowOne'>单价："+json.bean[i].buyPrice+"$</p>" +
			"<p class='ShowOne'>总价："+json.bean[i].buyTotalAmount+"$</p>" +
			"<p class='ShowOne'>成交量：0 &nbsp;好评率：99.49%</p>" +
		"</dd>" +
		"<dd id='ShowD'style='width:30%;'>" +
			"<p class='ShowT'><b>"+json.bean[i].buyCny+" CNT</b></p>" +
			"<p class='ShowT'><button style='width:80px;' type='submit' id='submit2' class='btn btn-default'>"+msg+"</button></p>" +
		"</dd>" +
	"</dl>" +
	"<hr/>" +
"</div>"
;
*/
</script>
</html>
